package com.kfm.base.collection;

import com.kfm.base.movie.Student;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

/**
 * 泛型，参数化类型
 * 泛型的类型不能是基本数据类型
 */
public class Demo04 {

    public static void main(String[] args) {
        /*
          泛型传递给集合后，约束了集合元素的类型
            编译时做类型检查，运行时强制类型转换
            泛型擦除
         */
        List<Student> list = new Vector<>();
        Student student1 = new Student("张三", 89);
        Student student2 = new Student("李四", 78);

        list.add(student1);
        list.add(student2);

        Student student = list.get(0);

        Iterator<Student> iterator = list.iterator();

//        Student next = iterator.next();

        list.sort(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });
    }
}
